//
//  RXFrameLogColor.m
//  RXFrame
//
//  Created by srxboys on 2021/4/21.
//

#import "RXFrameLogColor.h"

static RXFrameLogColor * __LogPrint = nil;

@interface RXFrameLogColor()
@property (nonatomic, copy) NSMutableArray * apiMethodArray;
@property (nonatomic, copy) NSMutableDictionary * apiDictionary;
@end

@implementation RXFrameLogColor
+ (void)printLog:(BOOL)isError file:(char *)file line:(int)line method:(NSString *)method content:(NSString *)format {
    if ([RXFrameLogColor shareLogColor].enable) {

        NSString *filePath = [[NSString stringWithUTF8String:file] lastPathComponent];

        NSString * headerIdentification = @"👇👇👇👇👇👇👇";
        NSString * footerIdentification = @"👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉👉";
        if(isError) {
            headerIdentification = @"❌❌❌❌❌❌❌";
            footerIdentification = @"🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺";
        }

        NSString *LogHeader = [NSString stringWithFormat:@": %@ \n   Ⓕⓘⓛⓔ ⏩ %@\n   Ⓛⓘⓝⓔ ⏩ %d\n   Ⓕⓤⓝⓒⓣⓘⓞⓝ ⏩",headerIdentification, filePath, line];

        format = [NSString stringWithFormat:@"\n%@", format];
        format = [format stringByAppendingString:@"\n\n"];
        format = [format stringByAppendingString:footerIdentification];
        printf("\n");
        if(isError) {
            NSLog(@"%@ %@ \n%@", LogHeader, method,format);
        }
        else {
            NSLog(@"%@ %@ \n%@", LogHeader, method,format);
        }
        printf("\n");
    }
}

+ (RXFrameLogColor *)shareLogColor {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        __LogPrint = [[RXFrameLogColor alloc] init];
    });
    return __LogPrint;
}

- (instancetype)init {
    return [self initConfig];
}

- (instancetype)initConfig {
    if(__LogPrint) {
        return __LogPrint;
    }
    _apiMethodArray = [[NSMutableArray alloc] init];
    _apiDictionary = [[NSMutableDictionary alloc] init];
    return [super init];
}
@end
